package ucd.csi.comp30220.fall2011.oteop.airline;

import ucd.csi.comp30220.fall2011.oteop.airline.impl.AirlineClient;

public final class AirlineFinder {
    
    static { new AirlineFinder(); }
    public AirlineFinder() { }
    
    /**
     * Tries to find the Airline running somewhere on the network. 
     * 
     * @param code
     *              Airline code. "BA", for instance.
     *              
     * @return the Airline Flight if it can be found, <code>null</code> otherwise
     */
    public static Airline find(String code) {
        return find(code, 10*1000);
    }

    /**
     * Tries to find the Airline running somewhere on the network. 
     * 
     * @param code
     *              Airline code. "BA", for instance.
     * @param timeout 
     *              how long (ms) to wait for the Airline to be found
     *              
     * @return the Airline if it can be found, <code>null</code> otherwise
     */
    public static Airline find(String code, long timeout) {
        try {
            return new AirlineClient(code, timeout);
        } catch (Exception e) { 
            return null;
        }
    }

}
